﻿using Iworld.Backstage.Framework.AdministratorService;
using Iworld.ViewModel;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Iworld.Backstage.Framework
{
    /// <summary>
    /// 主框架视图模型基类
    /// </summary>
    public abstract class MainFrameViewModelBase : ViewModelBase
    {

        string pageName;
        string groupName;
        /// <summary>
        /// 跳转命令
        /// </summary>
        public UniversalCommand JumpCommand { get; set; }

        /// <summary>
        /// 登出命令
        /// </summary>
        public UniversalCommand LogoutCommand { get; set; }

        /// <summary>
        /// 修改自身密码
        /// </summary>
        public UniversalCommand EditSelfPasswordCommand { set; get; }

        /// <summary>
        /// 当前主要的页面名称
        /// </summary>
        public string PageName
        {
            get { return pageName; }
            set
            {
                if (this.pageName != value)
                {
                    this.pageName = value;
                    this.OnPropertyChanged("PageName");
                }
            }
        }

        /// <summary>
        /// 管理员所在组名称
        /// </summary>
        public string GroupName
        {
            get { return groupName; }
            set
            {
                if (this.groupName != value)
                {
                    this.groupName = value;
                    this.OnPropertyChanged("GroupName");
                }
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pageName">当前选中的菜单</param>
        public MainFrameViewModelBase(string pageName)
        {
            this.PageName = pageName;
            this.JumpCommand = new UniversalCommand(new Action<object>(Jump));
            this.LogoutCommand = new UniversalCommand(new Action<object>(Logout));
            this.EditSelfPasswordCommand = new UniversalCommand((p) => {
                IPop pop = BackstageViewModelService.Current.GetPop(Pop.修改自身密码);
                pop.Show();
            });
            GroupName=DataManager.GetValue<AdministratorExport>(DataKey.Administrator_Info).Group.Name;
        }

        /// <summary>
        /// 跳转
        /// </summary>
        /// <param name="parameter">参数</param>
        void Jump(object parameter)
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            string pageName = parameter.ToString();
            BackstageViewModelService.Current.JumpTo(pageName);
        }

        /// <summary>
        /// 登出
        /// </summary>
        /// <param name="parameter"></param>
        void Logout(object parameter)
        {
            this.ComfirmMsg("确认退出吗?", () => { 
               BackstageViewModelService.Current.JumpToDefaultPage();
            });
        }
    }
}
